﻿using System;
using System.Text.RegularExpressions;
using System.Windows.Data;

namespace Scrabble.Controls
{
    public class NotationToMarkupConverter : IValueConverter
    {
        public NotationToMarkupConverter()
        {
            BoldColor = "gray";
        }

        public string BoldColor { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var prologue = String.Format(@"<span style='color:{0}'>", BoldColor);
            const string epilogue = @"</span>";

            var markup = value.ToString();
            if (String.IsNullOrWhiteSpace(markup)) return markup;

            if (markup[0] == '[') return "<span style='color:gray'>" + markup + "</span>";

            markup = Regex.Replace(markup, @"\(", prologue);
            markup = Regex.Replace(markup, @"\)", epilogue);

            return markup;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}